package com.pirestupppai.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseFragment;
import com.pirestupppai.bean.LoginUser;
import com.pirestupppai.common.Constant;
import com.pirestupppai.ui.activity.FollowListActivity;

import butterknife.BindView;
import io.rong.imkit.fragment.ConversationListFragment;
import io.rong.imlib.model.Conversation;

import static com.pirestupppai.ui.activity.FollowListActivity.FOLLOW_TYPE_MESSAGE;

/**
 * 聊天消息
 *
 * @author: xiaoluo
 * @date: 2017-03-03 17:08
 */
public class IMFragment extends BaseFragment {

    @BindView(R.id.search_bar)
    RelativeLayout searchBar;
    @BindView(R.id.status_bar)
    View statusBar;

    @Override
    protected Context getFragmentContext() {
        return getActivity();
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.fragment_message;
    }

    @Override
    protected void initViews() {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) statusBar.getLayoutParams();
        params.height = Constant.HEIGHT_OF_STATUSBAR;
        params.width = Constant.WIDTH_OF_SCREEN;
        statusBar.setLayoutParams(params);

        ConversationListFragment fragment = (ConversationListFragment) getChildFragmentManager().findFragmentById(R.id.conversationlist);
        Uri uri = Uri.parse("rong://" + getActivity().getApplicationInfo().packageName).buildUpon()
                .appendPath("conversationlist")
                .appendQueryParameter(Conversation.ConversationType.PRIVATE.getName(), "false") //设置私聊会话非聚合显示
                .appendQueryParameter(Conversation.ConversationType.GROUP.getName(), "false")//设置群组会话非聚合显示
                .appendQueryParameter(Conversation.ConversationType.DISCUSSION.getName(), "false")//设置讨论组会话非聚合显示
                .appendQueryParameter(Conversation.ConversationType.SYSTEM.getName(), "false")//设置系统会话非聚合显示
                .build();

        fragment.setUri(uri);

    }


    @Override
    protected void initListeners() {
        searchBar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, FollowListActivity.class);
                intent.putExtra(Constant.IntentKey.FOLLOW_LIST_TYPE, FOLLOW_TYPE_MESSAGE);
                intent.putExtra(Constant.IntentKey.UID, LoginUser.getInstance().getId());
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initLogic() {
    }



}